package com.suoluo.zenadmin.common;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import net.paoding.rose.web.Invocation;

import com.google.gson.Gson;

public class CommonResp {

	/**
	 * 成功状态码
	 */
	public static String SUCCESS_CODE="00000000"; 
	
	/**
	 * 失败状态码
	 */
	public static String FAIL_CODE="11111111"; 
	
	/**
	 * 未登录状态码
	 */
	public static String ADMIN_NONLOGIN = "10000000";
	 
	private String resultCode;
	private String resultMsg;
	
	public static CommonResp SUCCESS = new CommonResp(SUCCESS_CODE,"操作成功");
	
	public static CommonResp FAIL = new CommonResp(FAIL_CODE,"操作失败");
	
	public CommonResp()
	{
		this.resultCode = SUCCESS_CODE;
	}
	
	
	public CommonResp(String resultCode, String resultMsg) {
		super();
		this.resultCode = resultCode;
		this.resultMsg = resultMsg;
	}


	public String getResultCode() {
		return resultCode;
		
		
	}
	public void setResultCode(String resultCode) {
		this.resultCode = resultCode;
	}
	public String getResultMsg() {
		return resultMsg;
	}
	public void setResultMsg(String resultMsg) {
		this.resultMsg = resultMsg;
	}
	
	public static void encodeResp(Invocation inv,Object resp) throws IOException{
		HttpServletResponse response = inv.getResponse();
		if (response.getContentType() == null) {
			response.setContentType("application/json;charset=UTF-8");
		}
		Gson gson = new Gson();
		String json = gson.toJson(resp);
		response.getWriter().write(json);
	}
}
